#!/bin/bash

tag_name=$1
vehicle_name=$2
firmware_name=$3

echo "Start compile ${tag_name}"

SourceCodeDir=/mnt/f/ardupilot
HwDefFileDir=/mnt/d/NFCY/SourceCode/NFCYv5

cd $SourceCodeDir

git checkout .

echo Swtich to branch ${tag_name}
git checkout ${tag_name}

echo update submodules
git submodule update --init --recursive

echo clean
./waf distclean

echo Set compile target
cp -r  $HwDefFileDir libraries/AP_HAL_ChibiOS/hwdef/NFCYv5
cp -r libraries/AP_HAL_ChibiOS/hwdef/NFCYv5/NFCYv5_bl.bin Tools/bootloaders/NFCYv5_bl.bin
./waf configure --board NFCYv5
echo Start compile
./waf ${vehicle_name}
echo Compile finished...
echo Copy fireware to target directory.
cp -f ./build/NFCYv5/bin/*.apj /mnt/d/NFCY/Firmware/${firmware_name}.apj

git checkout .